<template>
  <div>
    <van-nav-bar title="详情" left-arrow @click-left="router.back()" />

    <!-- 轮播 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(v, i) in item.images" :key="i">
        <van-image :src="v" style="width: 100%; height: 100%;"></van-image>
      </van-swipe-item>
    </van-swipe>
    <!-- 数据 -->
    <h3>{{ item.title }}</h3>
    <p>{{ item.word }}</p>
    <div style="display: flex; justify-content: space-between;">
      <span>单价：<b style="color: red;">¥{{ item.price }}</b> </span>
      <span>销量： {{ numberToSell(item.sell) }}</span>
    </div>
    <!-- 动作栏目 -->
    <van-action-bar>
      <van-action-bar-icon icon="chat-o" text="客服" @click="onClickIcon" />
      <van-action-bar-icon icon="cart-o" text="购物车" @click="onClickIcon" />
      <van-action-bar-icon icon="shop-o" text="店铺" @click="onClickIcon" />
      <van-action-bar-button type="danger" text="加入购物车" @click="onClickButton" />
    </van-action-bar>

  </div>
</template>


<script lang="ts" setup>
import { ListRawState } from '@/types';
import axios from 'axios';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { numberToSell } from '@/utils/tools'
import { useStore } from 'vuex';
import router from '@/router';
const route = useRoute();
const store = useStore()
const item = ref<ListRawState>({} as ListRawState);
const { id } = route.params;

const onClickIcon = () => console.log('点击图标');
const onClickButton = () => {
  // 加入购物车
  store.commit('addCart', {
    ...item.value,
    count: 1,
    state: false
  })
};
const getDetail = async () => {
  const resp = await axios.get('/api/list/' + id);
  item.value = resp.data
}
getDetail()

</script>


<style lang="scss">
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  height: 200px;

  img {
    width: 100%;
    height: 100%;
  }
}
</style>